import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDFunctionUnlock {
	/**编号(主键)*/
	id,
	/**开启天数*/
	limitDay,
	/**需求类型：--【1.角色等级】【2.vip等级】【3.主线关卡id】【4.权限卡id（月卡、大月卡等级）】【5.祝福技能id及其等级】【9.暂未开放】【11.接口获取】*/
	type,
	/**参数*/
	value,
	/**两个条件关系--1.与关系2.或关系*/
	conditiontype,
	/**需求类型：--【1.角色等级】【2.vip等级】【3.主线关卡id】【4.权限id（月卡、大月卡等级）】【9.暂未开放】*/
	type_2,
	/**参数*/
	value_2,

	/**枚举数量*/
	EnumCount
}



export class CDFunctionUnlock{
	/**编号(主键)*/
	public id: number;
	/**开启天数*/
	public limitDay: number;
	/**需求类型：--【1.角色等级】【2.vip等级】【3.主线关卡id】【4.权限卡id（月卡、大月卡等级）】【5.祝福技能id及其等级】【9.暂未开放】【11.接口获取】*/
	public type: number;
	/**参数*/
	public value: number[];
	/**两个条件关系--1.与关系2.或关系*/
	public conditiontype: number;
	/**需求类型：--【1.角色等级】【2.vip等级】【3.主线关卡id】【4.权限id（月卡、大月卡等级）】【9.暂未开放】*/
	public type_2: number;
	/**参数*/
	public value_2: number[];


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDFunctionUnlock.id: return this.id;
			case E_CDFunctionUnlock.limitDay: return this.limitDay;
			case E_CDFunctionUnlock.type: return this.type;
			case E_CDFunctionUnlock.value: return this.value;
			case E_CDFunctionUnlock.conditiontype: return this.conditiontype;
			case E_CDFunctionUnlock.type_2: return this.type_2;
			case E_CDFunctionUnlock.value_2: return this.value_2;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDFunctionUnlock.id: this.id = v; break;
			case E_CDFunctionUnlock.limitDay: this.limitDay = v; break;
			case E_CDFunctionUnlock.type: this.type = v; break;
			case E_CDFunctionUnlock.value: this.value = v; break;
			case E_CDFunctionUnlock.conditiontype: this.conditiontype = v; break;
			case E_CDFunctionUnlock.type_2: this.type_2 = v; break;
			case E_CDFunctionUnlock.value_2: this.value_2 = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDFunctionUnlock> = new HashMap<number, CDFunctionUnlock>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDFunctionUnlock[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDFunctionUnlock();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].limitDay = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].value = [];
			const attrArray = list[i].value;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].conditiontype = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].type_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].value_2 = [];
			const attrArray = list[i].value_2;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDFunctionUnlock{
		return this.datas ? this.datas.get(id) : null;
	}
}
